package com.njitzx.controller.temp;

import com.njitzx.annotation.Type;
import com.njitzx.entity.dto.LoginDTO;
import com.njitzx.entity.vo.CodeVO;
import com.njitzx.entity.vo.LoginVO;
import com.njitzx.entity.vo.Result;
import com.njitzx.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;


    @Type
    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO loginDTO) {
        LoginVO loginVO = loginService.login(loginDTO);
        return Result.success(loginVO);
    }

    @GetMapping("/captchaImage")
    public Result captchaImage() {
        CodeVO codeVO = loginService.getCode();
        return Result.success(codeVO);
    }
    @Type
    @PostMapping("/captchaLogin")
    public Result loginByCode(@RequestBody LoginDTO loginDTO) {
        LoginVO loginVO = loginService.loginCode(loginDTO);
        return Result.success(loginVO);
    }

    @PostMapping("/logout")
    public Result logout() {
        return Result.success();
    }

    @GetMapping("/sendPhoneCode")
    public  Result setPhoneCode(String phone){
        loginService.setPhoneCode(phone);
        return  Result.success();
    }
    @Type
    @PostMapping("/login/phone")
    public Result loginByPhone(@RequestBody LoginDTO loginDTO) {
        LoginVO loginVO = loginService.loginByPhone(loginDTO);
        return Result.success(loginVO);
    }

}
